package projekty.stoper_wielowatkowosc;

import javax.swing.*;
import java.awt.*;

public class PanelStopera extends JPanel implements Runnable {
    public int x = 0;
    Thread t;

    PanelStopera() {
        if (t == null)
            t = new Thread(this);
        t.start();
    }

    @Override
    public void run() {
        for (; ; ) {
            repaint();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
    }

    @Override
    public void paintComponent(Graphics g) {
        g.setColor(new Color(0, 0, 0));
        g.fillRect(0, 0, 400, 400);
        g.setColor(new Color(208, 207, 204));
        g.fillOval(0, 0, 400, 400);
        g.setColor(Color.black);

        double kat;
        int x1, y1, x2, y2, z;
        z = 3;
        for (int i = 0; i < 12; i++) {
            kat = 2 * Math.PI * (i / 12.0);
            x2 = (int) (180 * Math.cos(kat)) + 200;
            y2 = (int) (180 * Math.sin(kat)) + 200;
            g.drawString(z + "", x2, y2);
            z++;
            if (z > 12) {
                z = 1;
            }
        }
        kat = 2 * Math.PI * (x / 60.0) - (Math.PI / 2);
        x1 = (int) (160 * Math.cos(kat));
        y1 = (int) (160 * Math.sin(kat));
        g.drawLine(200, 200, 200 + x1, 200 + y1);
        x++;
        if (x >= 60) { // jesli ilosc sekund jest wieksza od 60 ustaw ja na 0
            x = 0;
        }
    }
}
